Skip to content

Key map as data: DM_KBD_MAP gives the Mac keyboard a right stick - #1535

Closed
MenAtCafe wants to merge 1 commit into
seedds:mainfrom
MenAtCafe:keyboard-map
Closed

MenAtCafe wants to merge 1 commit into
seedds:mainfrom
MenAtCafe:keyboard-map

Conversation

@MenAtCafe

@MenAtCafe MenAtCafe commented Nov 6, 2026 •

Copy link
Copy Markdown

The Mac keyboard has no right stick. A 3D game's camera can only be turned with Shift and the arrow keys, or with a controller, which leaves the keyboard unusable for anything that needs a camera. The map is also a switch on virtual key codes inside front_mac.m, so changing one key means editing C.

pad_kbd.h holds the map as a table: 25 actions, up to four keys each, with the layout that was compiled in as the default, so nothing changes for a player who sets nothing. DM_KBD_MAP overrides it in the shape DM_HID_MAP already uses (A=C,B=X,RSTICK_UP=I), and a named action's keys are replaced rather than added to.

front_mac.m keeps one bitmask of the actions held and one byte per key code recording the action it went down as, so an arrow pressed with Shift still comes back up as the right stick it went down as, whatever Shift does meanwhile. push() now reads that bitmask, which removes the old key-code switch and the nine globals it fed.

Tests: dm/host/tests/t_pad_kbd.c has 44 checks over the default map, the override, alternates and a key that moves between actions.

Checked on a rebase onto today's main: the Mac host builds, the host unit tests pass, and test_env_switches, test_docs, test_lint_c, test_lint_python and test_architecture pass.

Front-ends: new: DM_KBD_MAP, a configurable keyboard map in env.txt

@github-actions github-actions Bot added host The Horizon host: SVCs, services, threads, memory (dm/host) mac The Mac front end and app (dm/mac, front_mac.m) docs Documentation labels Nov 6, 2026
@MenAtCafe MenAtCafe changed the title Key map as data: DM_KBD_MAP for the Mac keyboard Key map as data: DM_KBD_MAP gives the Mac keyboard a right stick Nov 14, 2026
@MenAtCafe
MenAtCafe force-pushed the keyboard-map branch 3 times, most recently from a54e374 to a7ca288 Compare November 15, 2026 06:19
The Mac front end's key map was a switch on virtual key codes: A B X Y on J K U I, arrows on the D-pad, and no
keys at all for the right stick, which left a 3D game's camera to Shift + arrows or a controller.

pad_kbd.h holds the map as a table, 25 actions with up to four keys each, and parses an override in the shape
DM_HID_MAP already uses. front_mac.m keeps one bitmask of held actions and the action each key code went down as,
so an arrow pressed with Shift still comes back up as the right stick it went down as. The default map is the one
that was compiled in, so nothing changes for a player who does not set the variable.

44 checks in dm/host/tests/t_pad_kbd.c, a row in docs/env_switches.tsv and a paragraph in docs/playing.md.

Front-ends: new: DM_KBD_MAP, a configurable keyboard map in env.txt
@seedds

seedds commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Thanks for the keyboard map and the 44 focused checks. I’m closing this older implementation in favor of #3141, which proposes a shared controls file for configurable keyboard bindings and controller remaps. Main still has a fixed keyboard map. The key-release case from this PR is worth carrying into that work. When an arrow is pressed with Shift and released after Shift goes up, the release still has to clear the right-stick action.

@seedds seedds closed this Nov 26, 2026
@MenAtCafe
MenAtCafe deleted the keyboard-map branch November 26, 2026 16:38
chgpalmer added a commit to chgpalmer/nxnative that referenced this pull request Nov 29, 2026
The Mac front end's half of the controller mapping (host/input: keymap.h, the remap in
hle_hid.c):

- In the game (front_mac.m, keyboard_mac.h): the keyboard goes through the map in
  place of the fixed key table, Shift, Control and Option keys included (flagsChanged).
  Each player's controller table goes to the host (dm_pad_map_set) at the start and
  after every change.
- The mouse (mouselook_mac.h): with a mouse direction bound, a click on the game
  captures the pointer and its movement goes through keymap_mouse.h at 120 Hz, to
  player 1's sticks and buttons, or to the motion sensor as a controller turned in the
  hands (dm_motion_set_switch: upright in handheld mode, flat docked). Esc, a focus
  loss or the panel lets it go.
- The settings window (Launcher.swift): Controls › Controller mapping › Customize…:
  a tab per player 1-8; player 1 has its keyboard and mouse or its controller;
  click a row and press a key or chord, click a mouse button, or press a controller's
  button or push its stick; right-click for Clear, Add Input… or a mouse direction;
  Mouse and trackpad puts the mouse on a stick or the motion controls with its
  sensitivity and Invert Y axis; a Preset menu per device (keymap_presets.h). Kept as
  the saved choice launcher.DM_KEYMAP, which launcher.c checks with the host's parser.
- In the game, Window › Controller Mapping… (⌘⇧K, keymap_panel_mac.h) is the same map
  while playing: a change applies at once and is saved for the next start.
- pad_apple.h's dm_pad_state is now the one reading of a GameController pad as the
  Switch's, used by the host's pad_read and the settings window's press-to-bind
  (pad_bridge.m).

Covers seedds#2346 (mouse as a stick), seedds#2392's and seedds#356's asks (mouse look, the camera on
plain arrows), the keyboard part of seedds#386 and seedds#2006's modifier keys; keys are tracked
as pressed, so Shift let go before an arrow does not leave the right stick held (seedds#1535).

Tests: test_launcher_storage (the window with the sheet's model), test_nsp_mac_app,
test_docs, test_env_switches.

Front-ends: new: launcher.DM_KEYMAP is a saved choice, checked by the host's parser (docs/frontends.md, Saved choices)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation host The Horizon host: SVCs, services, threads, memory (dm/host) mac The Mac front end and app (dm/mac, front_mac.m)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants